package com.btashov.stringarray;

import java.util.HashSet;

/**
 * @author Bahtiyar Tashov <btashov@gmail.com>
 */
public class CheckUniqueness {

    public static boolean isUniqueChars(String sentence) {
        if (sentence == null || sentence.isEmpty()) {
            throw new IllegalArgumentException("String argument is null or empty.");
        }

        HashSet<Character> set = new HashSet<Character>();
        for (char character : sentence.toCharArray()) {
            if (!set.add(character)) {
                return false;
            }
        }
        return true;
    }


    public static boolean isUniqueCharsNotRefactored(String sentence) {
        if (sentence == null || sentence.isEmpty()) {
            throw new IllegalArgumentException("String argument is null or empty.");
        }
        char[] characters = sentence.toCharArray();
        HashSet<Character> set = new HashSet<Character>();
        for (char character : characters) {
            if (!set.add(character)) {
                return false;
            }
        }
        return true;
    }
}
